Forewords
Currenltly, the only mandatory key is ptype which takes either plot or polar.
There is no mandatory value for any sections other than that,
however the func and funcx values are very sensitive
(because they are parsed using a very simple load(<code string>) function).
You can also remove the ptype and manually call the functions in the TIC() functions.
Also, use ... as the variable when defining functions!
{
func = "1" -- [string] <compilable to function>
funcx = "..." -- [string] <compilable to function>
start = -100 -- [number]
finish = 100 -- [number]
prec = 0.1 -- [number]
color = 2 -- [number]
label = "function" -- [string]
ptype = plot -- <function>: plot, polar. // planned: plot3d, polar3d, plotiz
}
For a polar() function, consider func as a polar function,
for a normal plot(), if you only define func, the code behaves as a normal function on the 2d plane (y=func(x)).
Changing funcx results in a curve of lambda=(funcx(t),func(t)).
There is currently no support for adding custom/several function during running the cart, but you can add your custom functions to "Add functions manually" section (or in the source code) and navigate through the function/pages with Up/Down arrow keys.
Update 2024-11-09
I have learned that there are legit ways like using lsp-lua to document code. It is also very important to note that this is a very experimental work and not ready for day to day use, but I'm aiming to make it versatile enough to replace online services I use. This is UNSTABLE PRE-ALPHA I guess. The code license is GPL-3.0, the document license is CC BY-SA 4.0.
Metadata
This is still undecided!
-- title: Plotter
-- author Behnam (Wired Unwell)
-- desc: A simple experimental plotter for TIC-80
-- site: wired_unwell.codeberg.page
-- license: GPL-3.0
-- version: 0.1
-- script: lua
-- input: keyboardInitialize variables and basic functions
o={x=120,
y=68,
z=10}
fnsi=1
sin=math.sin
cos=math.cos
log=math.log
pi=math.pi2D Plane
function plot(ptable)
local ll = ptable.start or -100
local rr = ptable.finish or 100
local precision = 0.1 or ptable.prec
local color = ptable.color or 1
local label = ptable.label or "function"
local xfunc = ptable.funcx or "..."
local yfunc = ptable.func or "1"
local y = load("return "..yfunc)
local x = load("return "..xfunc)
for t=ll,rr,precision do
pix(o.x + 10 * x(t/10),
o.y - 10 * y(t/10),
color)
end
math.randomseed(y(ll)+y(0)+y(rr))
local lll = math.random(ll,rr)
print(label,
o.x +10 * x(lll/10),
o.y -10 * y(lll/10),
color,false,1,true)
end2D Plane - Polar
function polar(ptable)
local ll = -pi or ptable.start
local rr = pi or ptable.finish
local precision = 0.01 or ptable.prec
local color = ptable.color or 2
local label = ptable.label or "function"
local rfunc = ptable.func or "1"
local r = load("return "..rfunc)
for t=ll,rr,precision do
local x = o.x + 10 * r(t) * math.cos(t)
local y = o.y + 10 * r(t) * math.sin(t)
pix(x,y,color)
end
math.randomseed(r(ll)+r(0)+r(rr))
local lll = math.random(ll//1,rr//1)
print(label,
o.x + 10 * r(lll) * math.cos(lll),
o.y + 10 * r(lll) * math.sin(lll),
color,false,1,true)
endAxis
function axis2d()
line(0,o.y,
240,o.y,
12)
tri(240,o.y,
235,o.y-5,
235,o.y+5,
12)
line(o.x,0,
o.x,136,
12)
tri(o.x,0,
o.x-5,5,
o.x+5,5,
12)
endAdd functions manually
-- ADD FUNCTIONS MANUALLY
fns={
{
func="...^3-2*...+...",
ptype=plot,
label="function"
},
{
funcx="2*sin(...)^2",
func="3*cos(...)",
ptype=plot,
label="curve"
},
{
func="2*sin(3*...)+3*cos(2*...)",
ptype=polar,
label="polar"
},
{
func = "1",
funcx = "...",
start = -100,
finish = 100,
color = 4,
label = "template",
ptype = plot,
}
}TIC
function TIC()
-- t=time()
if btnp(0) and fnsi>1 then fnsi = fnsi - 1 end -- up -- key 58
if btnp(1) and fnsi<#fns then fnsi = fnsi + 1 end -- do -- key 59
-- if btnp(2) then ; end -- le -- key 60
-- if btnp(3) then ; end -- ri -- key 61
cls(13)
axis2d()
fns[fnsi].ptype(fns[fnsi])
endCart data
-- <TILES>
-- 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc
-- 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c
-- 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc
-- 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c
-- 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
-- 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
-- 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
-- 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
-- </TILES>
-- <WAVES>
-- 000:00000000ffffffff00000000ffffffff
-- 001:0123456789abcdeffedcba9876543210
-- 002:0123456789abcdef0123456789abcdef
-- </WAVES>
-- <SFX>
-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
-- </SFX>
-- <TRACKS>
-- 000:100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-- </TRACKS>
-- <PALETTE>
-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
-- </PALETTE>